<!DOCTYPE html>
<!--
  ~ Copyright (c) 2017.
  ~ @author fff
  ~ 17-10-24 下午4:34
  ~
  -->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>合作方管理</title>
</head>
<body>
<div th:fragment="main" id="addCooperator">
    <link rel="stylesheet" th:href="@{/css/cooperatorGroup/addCooperator.css}">
    <div class="content-title">
        <p><span>合作方管理</span>&nbsp;>&nbsp;<span>新建合作方</span></p>
    </div>
    <div class="content-bar">
        <form class="form-horizontal clearfix col-xs-offset-1">
            <div class="form-group">
                <label class="form-label" for="cooperatorName">单位名称&nbsp;:&nbsp;</label>
                <input type="text" id="cooperatorName" class="form-input" placeholder>
                <label class="form-label" for="mode">合作模式&nbsp;:&nbsp;</label>
                <input type="text" id="mode" name="mode" class="form-input" placeholder>
            </div>

            <div class="form-group">
                <label class="form-label" for="credit">信用度&nbsp;:&nbsp;</label>
                <input type="text" id="credit" name="credit" class="form-input" placeholder>
                <label class="form-label" for="copLevel">合作级别&nbsp;:&nbsp;</label>
                <input type="text" id="copLevel" name="copLevel" class="form-input" placeholder>
            </div>

            <div class="form-group">
                <label class="form-label" for="leader">责任人&nbsp;:&nbsp;</label>
                <input type="text" id="leader" name="leader" class="form-input" placeholder>
                <label class="form-label" for="telephone">联系电话&nbsp;:&nbsp;</label>
                <input type="text" id="telephone" name="telephone" class="form-input" placeholder>
            </div>

            <div class="form-group">
                <label class="form-label" for="authentication">认证情况&nbsp;:&nbsp;</label>
                <input type="text" id="authentication" name="authentication" class="form-input" placeholder>
                <label class="form-label" for="certificate">相关资质&nbsp;:&nbsp;</label>
                <input type="text" id="certificate" name="certificate" class="form-input" placeholder>
            </div>

            <div class="form-group">
                <label class="form-label" for="resource">人员储备情况&nbsp;:&nbsp;</label>
                <input type="text" id="resource" name="resource" class="form-input" placeholder>
            </div>
            <div class="form-group">
                <label class="form-label" for="note">备注&nbsp;:&nbsp;</label>
                <textarea class="form-input" id="note" name="note" cols="" rows="4"></textarea>
            </div>


            <div class="form-group">
                <!-- <input type="button" value="返回" class="btn btn-default pull-right cancel" id="cancel"> -->
                <!-- <input type="button" value="保存" class="btn btn-primary pull-right save" id="save"> -->
                <div class="footer">
                    <a id="save" class="btn btn-cyan btn-bg" role="button">保存</a>
                    <a id="cancel" class="btn btn-cyan btn-bg" href="#qualitycontrol-cooperatorGroup-cooperator"
                       role="button">返回</a>
                </div>
            </div>

        </form>

        <script th:src="@{/assets/jquery/plugins/jquery.ui.widget.js}"></script>
        <script th:src="@{/assets/jquery/plugins/jquery.iframe-transport.js}"></script>

        <script>
            // 新建
            $('#save').on('click', function () {


                if ($("#cooperatorName").val().trim().length == 0) {
                    toastr.error("单位名称不得为空！");
                    return;
                }
//                if ($("#mode").val().length == 0) {
//                    toastr.error("合作模式不得为空！");
//                    return;
//                }
//                if ($("#credit").val().length == 0) {
//                    toastr.error("信用度不得为空！");
//                    return;
//                }
//                if ($("#copLevel").val().length == 0) {
//                    toastr.error("合作级别不得为空！");
//                    return;
//                }
//                if ($("#leader").val().length == 0) {
//                    toastr.error("责任人不得为空！");
//                    return;
//                }
//                if ($("#telephone").val().length == 0) {
//                    toastr.error("联系电话不得为空！");
//                    return;
//                }
//                if ($("#authentication").val().length == 0) {
//                    toastr.error("认证情况不得为空！");
//                    return;
//                }
//                if ($("#certificate").val().length == 0) {
//                    toastr.error("相关资质不得为空！");
//                    return;
//                }
//                if ($("#resource").val().length == 0) {
//                    toastr.error("人员储备情况不得为空！");
//                    return;
//                }
//                if ($("#note").val().length == 0) {
//                    toastr.error("备注不得为空！");
//                    return;
//                }

                if ($("#cooperatorName").val().trim().length > 25) {
                    toastr.error("单位名称不得超过25个字符！");
                    return;
                }
                if ($("#mode").val().length > 25) {
                    toastr.error("合作模式不得超过25个字符！");
                    return;
                }
                if ($("#credit").val().length > 25) {
                    toastr.error("信用度不得超过25个字符！");
                    return;
                }
                if ($("#copLevel").val().length > 25) {
                    toastr.error("合作级别不得超过25个字符！");
                    return;
                }
                if ($("#leader").val().length > 25) {
                    toastr.error("责任人不得超过25个字符！");
                    return;
                }
                if ($("#telephone").val().length > 25) {
                    toastr.error("联系电话不得超过25个字符！");
                    return;
                }
                if ($("#authentication").val().length > 25) {
                    toastr.error("认证情况不得超过25个字符！");
                    return;
                }
                if ($("#certificate").val().length > 25) {
                    toastr.error("相关资质不得超过25个字符！");
                    return;
                }
                if ($("#resource").val().length > 25) {
                    toastr.error("人员储备情况不得超过25个字符！");
                    return;
                }
                if ($("#note").val().length > 250) {
                    toastr.error("备注不得超过250个字符！");
                    return;
                }
                var formData = {
                    "name": $("#cooperatorName").val(),
                    "mode": $("#mode").val(),
                    "credit": $("#credit").val(),
                    "copLevel": $("#copLevel").val(),
                    "leader": $("#leader").val(),
                    "telephone": $("#telephone").val(),
                    "authentication": $("#authentication").val(),
                    "certificate": $("#certificate").val(),
                    "resource": $("#resource").val(),
                    "note": $("#note").val()
                };

                $.ajax({
                    url: contextPath + '/Cooperator/createCooperator',
                    type: 'POST',
                    data: JSON.stringify(formData),
                    cache: false,
                    contentType: "application/json",
                    success: function (data) {
                        if(data.code == 1) {
                            toastr.success("新建合作方，保存成功!");
                            location.hash = "#qualitycontrol-cooperatorGroup-cooperator";
                        }else{
                            toastr.error(data.message,'创建失败！');
                        }
                        console.log(data);

                    },
                    error: function (data) {
                        toastr.error("操作失败，请稍后再试!");
                    }
                });
            });


            // 取消
            $('#cancel').on('click', function () {
                $('#add_form')[0].reset();
            });


        </script>
</body>
</html>

